﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Core;
public partial class ThongKe_PageCanBoDonVi : System.Web.UI.Page
{
    public int total = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (MaDonVi > 0)
                BinData(MaDonVi);
                            else

                BinData(-1);

            ddlDonVi.DataSource = DonVi.All();
            ddlDonVi.DataValueField = "ID";
            ddlDonVi.DataTextField = "TenDonVi";
            ddlDonVi.DataBind();
            ddlDonVi.SelectedValue = MaDonVi.ToString();
        }
    }
    public int MaDonVi
    {
        get
        {
            if (Request.QueryString["MaDonVi"] != null)
                return int.Parse(Request.QueryString["MaDonVi"]);
            return -1;
        }
    }
    void BinData(int maDonVi)
    {

        int pageSize = 10;

        int pageNum = 1;
        if (Request.QueryString[PagingControl1.QueryStringKey] != null)
        {
            pageNum = int.Parse(Server.HtmlEncode(Request.QueryString[PagingControl1.QueryStringKey]));
        }
        else pageNum = 1;


        rptData.DataSource = CanBo.Paging_CanBo_TheoDonVi(pageSize, pageNum, maDonVi, out total);

        rptData.DataBind();

        PagingControl1.TotalRecord = total;
        PagingControl1.CurrentPage = pageNum;
        PagingControl1.PageSize = pageSize;

    }
    protected void btnRefresh_ServerClick(object sender, EventArgs e)
    {
        Response.Redirect(Request.Url.AbsolutePath);
    }

    protected void ddlDonVi_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("PageCanBoTheoDonVi.aspx?MaDonVi=" + ddlDonVi.SelectedValue);
    }
}